/******************************************************//**
 *    C++ library of linear algebra.
 *
 * Copyright (c) 2019-2029 Yi Zhang (zhangyiss@icloud.com)
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *********************************************************/

#ifndef _ALGEBRA_H
#define _ALGEBRA_H

inline static void vecset(double *x, double c, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        x[i] = c;
    }
    return;
}

inline static void veccpy(double *x, const double *y, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        x[i] = y[i];
    }
    return;
}

inline static void vecdiff(double *a, const double *b, const double *c, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        a[i] = b[i] - c[i];
    }
    return;
}

inline static void vecscale(double *a, double c, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        a[i] *= c;
    }
    return;
}

inline static void vecmul(double *a, const double *b, double c, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        a[i] = c*b[i];
    }
    return;
}

inline static double vecdot(const double *b, const double *c, size_t n)
{
    double s = 0.0;
    for (size_t i = 0; i < n; i++)
    {
        s += b[i]*c[i];
    }
    return s;
}

inline static bool veccheckbox(const double *h, const double *l, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        if (h[i] <= l[i]) return false;
    }
    return true;
}

inline static bool veccheckpos(const double *a, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        if (a[i] <= 0.0) return false;
    }
    return true;
}

inline static void vecbtm(double *x, const double *l, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        if (x[i] < l[i]) x[i] = l[i];
    }
    return;
}

inline static void vectop(double *x, const double *h, size_t n)
{
    for (size_t i = 0; i < n; i++)
    {
        if (x[i] > h[i]) x[i] = h[i];
    }
    return;
}

#endif // _ALGEBRA_H